pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut result = String::new();

    if num_str.is_empty() {
        return result;
    } else {
        let tmp = num_str.replace("(", " ").replace(")", "");
        let inputs = tmp.split(" ").collect::<Vec<&str>>();
        let input_base = inputs[1].parse::<u32>();
        if inputs.len() == 2 && input_base.is_ok() {
            let input_decimal = to_decimal(inputs[0], input_base.unwrap());
            result = convert(input_decimal as u32, to_base as u32);
        }
    }
    result
}

/// 将输入转换为10进制
fn to_decimal(input: &str, base: u32) -> usize {
    let mut result = 0usize;
    input.chars().rev().enumerate().for_each(|(index, num)| {
        result += num.to_digit(base).unwrap() as usize * base.pow(index as u32) as usize;
    });
    result
}

/// 将10进制转换为任意进制
fn convert(mut decimal_num: u32, to_base: u32) -> String {
    let mut result = Vec::new();
    let digits = [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
    ];

    while decimal_num > 0 {
        result.push(decimal_num % to_base);
        decimal_num /= to_base;
    }

    let mut result_string = String::new();
    while !result.is_empty() {
        result_string.push(digits[result.pop().unwrap() as usize]);
    }
    result_string
}
